import 'package:bot_toast/bot_toast.dart';
import 'package:flutter/material.dart';

class IndexPage3 extends StatefulWidget {
  @override
  _IndexPage3State createState() => _IndexPage3State();
}

class _IndexPage3State extends State<IndexPage3> {

  final List<Building> buildings = [
    Building(BuildingType.theater,'CineArts at the Empire','85 W Portal Ave'),
    Building(BuildingType.theater,'The Castro Theater','429 Castro St'),
    Building(BuildingType.theater,'Alamo Drafthouse Cinema','2550 Mission St'),
    Building(BuildingType.theater,'Roxie Theater','3117 16th St'),
    Building(BuildingType.theater,'United Artists Stonestown Twin','501 Buckingham Way'),
    Building(BuildingType.theater,'AMC Metreon 16','135 4th St #3000'),
    Building(BuildingType.restaurant,'K\'s Kitchen','1923 Ocean Ave'),
    Building(BuildingType.restaurant,'Chaiya Thai Restaurant','72 Claremont Blvd'),
    Building(BuildingType.restaurant,'La Ciccia','291 30th St'),

    Building(BuildingType.theater,'CineArts at the Empire','85 W Portal Ave'),
    Building(BuildingType.theater,'The Castro Theater','429 Castro St'),
    Building(BuildingType.theater,'Alamo Drafthouse Cinema','2550 Mission St'),
    Building(BuildingType.theater,'Roxie Theater','3117 16th St'),
    Building(BuildingType.theater,'United Artists Stonestown Twin','501 Buckingham Way'),
    Building(BuildingType.theater,'AMC Metreon 16','135 4th St #3000'),
    Building(BuildingType.restaurant,'K\'s Kitchen','1923 Ocean Ave'),
    Building(BuildingType.restaurant,'Chaiya Thai Restaurant','72 Claremont Blvd'),
    Building(BuildingType.restaurant,'La Ciccia','291 30th St'),
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('ListView组件'),
      ),
      body: ListView.builder(
        itemCount: buildings.length,
        itemBuilder: (context, index){
          return ItemView(
            position: index,
            building: buildings[index],
          );
        },
      ),
    );
  }
}

enum BuildingType { theater, restaurant }

class Building {
  final BuildingType type;
  final String title;
  final String address;

  Building(this.type, this.title, this.address);
}

class ItemView extends StatelessWidget {
  final int position;
  final Building building;

  const ItemView({Key key, this.position, this.building}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final icon = Icon(
      building.type == BuildingType.restaurant ? Icons.restaurant : Icons.theaters,
      color: Colors.blue[500],
    );

    return InkWell(
      onTap: (){
        print('item $position clicked');
        BotToast.showText(text: 'item $position clicked', align: Alignment(0, 0));
      },
      child: Row(
        children: <Widget>[
          Container(
            margin: EdgeInsets.all(16),
            child: icon,
          ),
          Expanded(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: <Widget>[
                Text(
                  building.title,
                  style: TextStyle(
                      fontSize: 20,
                      fontWeight: FontWeight.w500
                  ),
                ),
                Text(building.address)
              ],
            ),
          )
        ],
      ),
    );
  }
}

